import { request } from '@umijs/max';
import type {PermsItem, UserItem} from './data';

// user/list  页面专用接口
/** 获取规则列表 GET /api/user/list */
export async function queryUserList(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: UserItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/api/user/list', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 更新修改用户
export async function updateUser(data: Record<string, any>, options?: Record<string, any>) {
  return request('/api/user/list', {
    data,
    method: 'PUT',
    ...(options || {}),
  });
}

// 禁用用户
export async function lockUser(data: Record<string, any>, options?: Record<string, any>) {
  return request('/api/user/list', {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}

// 新增用户
export async function addUser(data: Record<string, any>, options?: Record<string, any>) {
  return request('/api/user/list', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

// 获取用户权限
export async function queryUserPerms(
  params: {
    uid?: any,
    isFirst?: string,
  },
  options?: Record<string, any>
) {
  return request<{
    data: PermsItem[];
    status: string;
  }>('/api/user/userPerms', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });

}

// 更新设置用户权限
export async function updateUserPerms(data: Record<string, any>, options?: Record<string, any>) {
  return request('/api/user/userPerms', {
    data,
    method: 'PUT',
    ...(options || {}),
  });
}

